<?php

//取某一页
function getpage($page=1,$pagesize=10)
{
    require 'dbcon.php';
    $offset=($page-1)*$pagesize;
    $sql="select a.*,b.nickname,c.name from posts a, users b ,categories c where a.user_id=b.id and  a.status!='trashed' and c.id=a.category_id limit {$offset},{$pagesize}";//定义查询语句
    $result=$db->query($sql);//执行查询语句
    $data=$result->fetch_all(MYSQLI_ASSOC);
    $db->close();
    return $data;
}
//算文章的总数
function getnum()
{
    require 'dbcon.php';
    $sql="select a.*,b.nickname,c.name from posts a, users b ,categories c where a.user_id=b.id and  a.status!='trashed' and c.id=a.category_id";//定义查询语句
    $result=$db->query($sql);//执行查询语句
    $num=$result->num_rows;//取结果集的数目
    return $num;
}

